﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.Prism.Mvvm;
using Microsoft.Practices.Prism.ViewModel;
using System.Windows.Documents;

namespace MergeTool.UI.ViewModels
{
    public abstract class MyCustomViewModelBase : BindableBase, INotifyDataErrorInfo
    {
        protected MyCustomViewModelBase()
        {
            this.ErrorsContainer = new ErrorsContainer<ValidationResult>(
                           this.RaiseErrorsChanged);
        }

        protected ErrorsContainer<ValidationResult> ErrorsContainer;

        public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;

        public bool HasErrors
        {
            get { return this.ErrorsContainer.HasErrors; }
        }



        public IEnumerable GetErrors(string propertyName)
        {
            return this.ErrorsContainer.GetErrors(propertyName);
        }

        protected void RaiseErrorsChanged(string propertyName)
        {
            var handler = this.ErrorsChanged;
            if (handler != null)
            {
                handler(this, new DataErrorsChangedEventArgs(propertyName));
            }
        }
    }
}
